#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QStyledItemDelegate>
#include <QAbstractItemView>
#include <QDebug>
#include <QMetaObject>
#include <QAction>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QAbstractItemView* view =     ui->comboBox->view();
    qDebug() << view->metaObject()->className();
    qDebug() << view->itemDelegate()->metaObject()->className();
    qDebug() << QApplication::style()->metaObject()->className();
    view->setMouseTracking(true);
    QMenu *file = new QMenu(this);
    QAction *open = new QAction("\tOpen CTRL+SHIFT+N\t",file);
    file->addAction(open);
    QMenu *edit = new QMenu(this);
    edit->setTitle("Edit");
    file->setTitle("File");
    QPalette palette = file->palette();
    palette.setColor(QPalette::Text, Qt::blue);
    file->setPalette(palette);
    // 使用样式表设置菜单文字颜色为白色，背景颜色为黑色
      QString styleSheet = "QMenuBar {"
                           "    color: blue;"


                           "    font-size: 16px;"
                           "    font-weight: bold;"

                            "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(100, 150, 200, 128), stop:0.5 white, stop:1 rgba(100, 150, 200, 128));"
                           "}"

                            "QMenuBar::item:selected{    font-size: 16px; border: 1px dashed #ADD8E6;}"

                           "QMenu {"
                                    "font-size: 14px;"
                                    "border: 1px solid yellow;"
                                    "border-radius: 3px;"
                                 "}"



                            "QMenu::item {"
                                               "margin: 4px;"
                                               "padding-top: 4px;"
                                               "padding-left: 4px;"
                                               "padding-right: 4px;"
                                               "padding-bottom: 4px;"
                                               "border-radius: 4px;"
                                        "}"

                            "QMenu::item:selected {"

                                    "border: 1px solid #ADD8E6;"
                                    "border-radius: 4px;"
                                "}";
    menuBar()->addMenu(file);
    menuBar()->addMenu(edit);
    file->setStyleSheet(styleSheet);
    menuBar()->setStyleSheet(styleSheet);
}

MainWindow::~MainWindow()
{
    delete ui;
}

